<?php

namespace addons\order\model;

/**
 * 种植
 *
 * @author shilinqing
 */
class RechargeModel extends \web\common\model\BaseModel {

    protected function _initialize() {
        $this->tableName = 'recharge_order';
    }
    public function getList($pageIndex = -1, $pageSize = -1, $filter = '', $order = 'id asc') {
        $m = new \addons\member\model\MemberAccountModel();
        $sql = 'select a.*,b.username from ' . $this->getTableName() . ' a,'.$m->getTableName().' b where a.user_id=b.id';
        if (!empty($filter))
            $sql .=  ' and '.$filter;
        return $this->getDataListBySQL($sql, $pageIndex, $pageSize, $order);
    }

    public function getPicById($id){
        $where['id'] = $id;
        return $this->where($where)->field('pic')->find();
    }
    
    public function getCountTotal($filter = '') {
        $sql = 'select sum(amount) c from ' . $this->getTableName() . ' where 1=1 ';
        if (!empty($filter))
            $sql .= ' and (' . $filter . ')';
        $result = $this->query($sql);
        if (count($result) > 0)
            return intval($result[0]['c']);
        else
            return 0;
    }

}
